﻿using HospitalSelfServiceMachine.Utils;
using HospitalSelfServiceMachine.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using MessageBoxImage = HospitalSelfServiceMachine.Bean.MessageBoxImage;
namespace HospitalSelfServiceMachine.Controls
{
    public static class MessageBox
    {
        
        public static bool Show(string messageBoxText, Window owner = null)
        {
            var msg = new HSMessageBox(messageBoxText);
            return GetWindow(msg, owner);
        }

        public static bool Show(string messageBoxText, MessageBoxImage imageType, MessageBoxButton messageBoxButton, Window owner = null)
        {
            var msg = new HSMessageBox(messageBoxText, imageType, messageBoxButton);
            return GetWindow(msg, owner);
        }



        private static bool GetWindow(HSMessageBox msg, Window owner = null)
        {
            bool flag=false;
            msg.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            if (owner != null)
            {
                msg.CreateMask();
                msg.Owner = owner;
                flag = (bool)msg.ShowDialog();
            }
            else
            {
                var win = ControlsHelper.GetDefaultWindow();
                if (win != null && win != msg)
                {
                    if (win.WindowState == WindowState.Minimized)
                        msg.BorderThickness = new Thickness(1);
                    msg.CreateMask();
                    msg.Owner = win;
                    flag = (bool)msg.ShowDialog();
                }
                else
                {
                    msg.BorderThickness = new Thickness(1);
                    msg.Show();
                }
            }
            return flag;
        }
    }
}
